﻿using BO.News;
using GUI.Extensions;
using System.Collections.Generic;
using Utilities.Entities;

namespace GUI.Controls.News
{
    public partial class EmbedGroup2 : System.Web.UI.UserControl
    {
        public const int ImageWidth = 240;
        private const int ImageHeight = 180;
        private const int TopHighlight = 1;
        private const int TopOther = 2;

        internal void DataBind(int zoneId1, int zoneId2)
        {
            var bo = CacheSettingExtensions.EnableCacheHtml
                         ? NewsBO_NoCache.GetInstance()
                         : NewsBO.GetInstance();
            var listNews = new List<NewsObject>();
            CategoryObject zone1 = null, zone2 = null;

            if (zoneId1 > 0)
            {
                zone1 = NewsBO.GetInstance().GetCategoryDetail(zoneId1);

                if (zone1 != null)
                {

                    var list1 =
                        zoneId2 > 0
                            ? bo.ImportNewsWhileNotEnough(zoneId1, TopHighlight, TopOther)
                            : bo.ImportNewsWhileNotEnough(zoneId1, TopHighlight * 2, TopOther * 2);
                    if (list1 != null && list1.Count > 0)
                    {
                        listNews.AddRange(list1);
                    }
                }
            }

            if (zoneId2 > 0)
            {
                zone2 = NewsBO.GetInstance().GetCategoryDetail(zoneId2);
                if (zone2 != null)
                {
                    var list1 = bo.ImportNewsWhileNotEnough(zoneId2, TopHighlight, TopOther);
                    if (list1 != null && list1.Count > 0)
                    {
                        listNews.AddRange(list1);
                    }
                }
            }

            ctrZone1.DataBind(zone1, zone2, listNews, ImageWidth, ImageHeight);
        }
    }
}